package 第二轮工作.东北石油大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DBSu {
    public static void main(String[] args) throws IOException {
        DBSuBean dbSuBean = null;
        List<DBSuBean> dbSuBeans = new ArrayList<>();
        String Url = "http://dqxxgcxy.nepu.edu.cn/szll/xzfc.htm";
        Connection connect = Jsoup.connect(Url);
        int i = 1;
        Document post = connect.post();
        for (Element mainConRCa : post.getElementsByClass("main_conRCa")) {
            for (Element element : mainConRCa.getElementsByTag("table")) {
                for (Element td : element.getElementsByTag("td")) {
                    for (Element a : td.getElementsByTag("a")) {
                        dbSuBean = new DBSuBean();
                        dbSuBean.setT_name(a.text());
                        System.out.println(a.text());
                        String attr = a.attr("href");
                        String substring = attr.substring(3, attr.length());
                        Connection connect1 = Jsoup.connect("http://dqxxgcxy.nepu.edu.cn/" + substring);
                        Document post1 = connect1.post();
                        for (Element vNewsContent : post1.getElementsByClass("v_news_content")) {
                            dbSuBean.setInfo(vNewsContent.text());
//                            System.out.println(vNewsContent.text());
                            dbSuBeans.add(dbSuBean);
                        }
                        i++;
                    }

                }

            }
            if (i > 14) {
                break;
            }
        }
        EasyExcel.write("src/Dbu.xlsx", DBSuBean.class).sheet("user").doWrite(dbSuBeans);

    }
}
